<template>
  <div class="app-container">
    <div class="operate-container">
      <el-button type="primary" @click="handleCreateProductAttr()" size="small">新 建</el-button>
    </div>
    <div class="table-container">
      <el-table
        :data="list"
        v-loading="listLoading"
        border
        size="small"
      >
        <el-table-column label="编号" width="200">
          <template slot-scope="scope">{{scope.row.specCode}}</template>
        </el-table-column>
        <el-table-column label="属性名称" width="200">
          <template slot-scope="scope">{{scope.row.specName}}</template>
        </el-table-column>
        <el-table-column label="属性描述">
          <template slot-scope="scope">{{scope.row.remarks}}</template>
        </el-table-column>
        <el-table-column label="状态" width="160">
          <template slot-scope="scope">{{scope.row.status}}</template>
        </el-table-column>
        <el-table-column label="创建日期" width="200">
          <template slot-scope="scope">{{scope.row.createDate}}</template>
        </el-table-column>
        <el-table-column label="最后修改日期" width="200">
          <template slot-scope="scope">{{scope.row.updateDate}}</template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEditRange(scope.row.specCode)">编辑属性值</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper"
        :page-size="listQuery.pageSize"
        :page-sizes="[5,10,15]"
        :current-page.sync="listQuery.pageNum"
        :total="total"
      ></el-pagination>
    </div>
    <el-dialog title="新建产品属性" :visible.sync="attrDialogVisible" width="500px" append-to-body :close-on-click-modal="false" class="form-dialog">
      <hcbk-create-product-attr v-if="attrDialogVisible" @after-create="handleAfterCreate"></hcbk-create-product-attr>
    </el-dialog>
    <el-dialog title="编辑产品属性值" :visible.sync="rangeDialogVisible" width="800px" append-to-body :close-on-click-modal="false" class="form-dialog">
      <hcbk-product-attr-range v-if="rangeDialogVisible" :code="attrCode"  @after-edit="handleAfterEdit"></hcbk-product-attr-range>
    </el-dialog>
  </div>
</template>
<script>
import { getProductAttrList, createProductAttr } from "@/api/product";
import CreateProductAttr from "./components/createProductAttr.vue";
import ProductAttrRange from "./components/productAttrRange.vue";
export default {
  name: "ProductAttr",
  components: {
    HcbkCreateProductAttr: CreateProductAttr,
    HcbkProductAttrRange: ProductAttrRange
  },
  data() {
    return {
      list: null,
      total: null,
      listLoading: true,
      listQuery: {
        pageNum: 1,
        pageSize: 10
      },
      attrDialogVisible: false,
      attrCode: "",
      rangeDialogVisible: false
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.listLoading = true;
      getProductAttrList(this.listQuery).then(response => {
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
    handleCreateProductAttr() {
      this.attrDialogVisible = true;
    },
    handleEditRange(code) {
      this.attrCode = code
      this.rangeDialogVisible = true;
    },
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    handleAfterCreate(result) {
      this.attrDialogVisible = false;
      if (result) {
        this.getList();
      }
    },
    handleAfterEdit(){
      this.rangeDialogVisible = false
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.form-dialog /deep/ .el-dialog__body {
  padding: 18px;
}
</style>


